var a = require("../../utils/api.js"), t = getApp();

Page({
    data: {
        value: "",
        allmoney: "0.00",
        than: !1,
        curStatus: 1,
        info: "",
        loading: !1
    },
    onLoad: function(e) {
        var o = this;
        wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        }), a.getMember({
            openid: t.globalData.openid
        }).then(function(a) {
            o.setData({
                allmoney: a.data.m_money
            });
        }), a.getUserCommission({
            openid: t.globalData.openid
        }).then(function(a) {
            1 == a.errno ? o.setData({
                info: a.data,
                page: 2
            }) : o.setData({
                info: "",
                page: 2
            }), wx.hideLoading();
        });
    },
    onShow: function(e) {
        a.getMember({
            openid: t.globalData.openid
        }).then(function(a) {
            that.setData({
                allmoney: a.data.m_money
            });
        });
    },
    money: function(a) {
        var t = this, e = a.detail.value;
        if (parseFloat(e) > parseFloat(t.data.allmoney)) t.setData({
            than: !0
        }); else {
            if (parseFloat(e) < 0) return 0;
            t.setData({
                than: !1,
                value: e
            });
        }
    },
    tap: function(e) {
        wx.showLoading({
            title: "Loading..."
        });
        var o = this, n = e.currentTarget.dataset.id;
        o.setData({
            curStatus: n
        }), 1 == n ? a.getUserCommission({
            openid: t.globalData.openid
        }).then(function(a) {
            1 == a.errno ? o.setData({
                info: a.data,
                page: 2
            }) : o.setData({
                info: "",
                page: 2
            }), wx.hideLoading();
        }) : 2 == n && a.getUserGetCash({
            openid: t.globalData.openid
        }).then(function(a) {
            console.log(a), 1 == a.errno ? o.setData({
                info: a.data,
                page: 2
            }) : o.setData({
                info: "",
                page: 2
            }), wx.hideLoading();
        }), wx.hideLoading();
    },
    all: function() {
        0 != this.data.allmoney ? this.setData({
            value: this.data.allmoney
        }) : wx.showToast({
            title: "余额不足",
            icon: "none",
            duration: 2e3
        });
    },
    btn: function(t) {
        var e = this, o = e.data.value;
        if ("" == o) return !1;
        var n = {
            openid: wx.getStorageSync("openid"),
            money: parseFloat(o),
            form_id: t.detail.formId
        };
        a.applyGetCash(n).then(function(a) {
            var t = parseFloat(e.data.allmoney) - o;
            t < 0 && (t = 0), 1 == a.errno && e.setData({
                allmoney: t.toFixed(2)
            }), wx.showToast({
                title: a.message,
                icon: "none",
                duration: 2e3
            });
        });
    }
});